#include "config.h"

Config::Config() {
    // 默认配置
    port = 9527;
    log_mode = 0;
    trig_mode = 0;
    listen_trig_mode = 0;
    connect_trig_mode = 0;
    opt_linger = 0;
    sql_num = 5;
    thread_num = 5;
    close_log = 0;
    actor_model = 0;

    db_name = "server_db";
    db_uname = "root";
    db_passwd = "root";
}

void Config::setConfig(int argc, char* argv[]) {
    // 自定义输入参数
    int opt;
    const char opt_str[] = "p:l:m:L:s:t:C:a";
    while ((opt = getopt(argc, argv, opt_str)) != -1) {
        switch (opt) {
            case 'p': {
                port = atoi(optarg);
                break;
            }
            case 'l': {
                log_mode = atoi(optarg);
                break;
            }
            case 'm': {
                trig_mode = atoi(optarg);
                break;
            }
            case 'L': {
                opt_linger = atoi(optarg);
                break;
            }
            case 's': {
                sql_num = atoi(optarg);
                break;
            }
            case 't': {
                thread_num = atoi(optarg);
                break;
            }
            case 'C': {
                close_log = atoi(optarg);
                break;
            }
            case 'a': {
                actor_model = atoi(optarg);
                break;
            }
            default: {
                exit(1);
            }
        }
    }
}
